
/* Device class */
#ifdef 	__DEVICE_CLASS__  


#include "USART.h"
#include <stdarg.h>
#include "AuxPort.h"

#define   THE_DEVICE		dev
#define   DEVICE_NAME	"My_Device"


enum
{
	WRITE,
	READ,
	INIT
}DEV_METHOD;



const char Dev_Name[] = DEVICE_NAME;  

typedef struct
{
		const char *DeviceName;
		void (*Init)(void);
		void (*Device)(void);
		int (*Write)(unsigned long Address, void* Data, unsigned char BytesCount );
		int (*Read)(unsigned long Address, void* Data, unsigned char BytesCount );
		int (*Call)(unsigned char Method, ...);
}DEVICE;

static void Init ( void )
{
	
}

static void Start ( void )
{
	
}


int Write ( unsigned long Address, void* Data, unsigned char BytesCount )
{

	return 0;
}

int Read ( unsigned long Address, void* Data, unsigned char BytesCount )
{

	return 0;
}


/* int sprintf(char *out, const char *format, ...) */
/* { */
/* 	va_list args; */
        
/* 	va_start( args, format ); */
	
/* 	return print( &out, format, args ); */
/* } */

int Call ( unsigned char Method, ... )
{
	va_list args;
	
	va_start( args, Method );

	switch( Method )
	{
		case WRITE:
			Write(va_arg(args, int), va_arg(args, void*), va_arg(args, unsigned char )); 	
			break;


		case READ:

			break;

		default:
			;
	}
}


const DEVICE THE_DEVICE = 
{
	Dev_Name,
	Init,
	Write,
	Read,
	Call
};

#define   REG_PRESSED_KEY		0
#define   REG_KEYS_STATUS		1

typedef struct 
{	
		unsigned 	ZERO 		  	: 	1;
		unsigned 	ONE 		  	: 	1;	    	
		unsigned 	TWO 		  	: 	1;
		unsigned 	THREE 	  	: 	1;
		unsigned 	FOUR 		  	: 	1;
		unsigned 	FIVE 		  	: 	1;
		unsigned		SIX 		  	: 	1;
		unsigned 	SEVEN 	  	: 	1; 
		unsigned 	EIGHT 	  	: 	1;
		unsigned 	NINE 		  	: 	1;	    	
		unsigned 	STAR		  	: 	1;
		unsigned 	POUND		  	: 	1;	/* '#' key */
		unsigned 	K_OFF		  	: 	1;
		unsigned 	MENU 		  	: 	1;
		unsigned 	CLEAR 	  	: 	1;
		unsigned		OKAY		  	: 	1;
		unsigned 	sHOOK		  	:	1;
		unsigned 	sON_OFF	  	:	1;
		unsigned 	SIM_INT		:	1;
		unsigned		SIM_EXT		:	1;

}KEYPAD;


void dev_Test ( void )
{
	unsigned char PrKey;
	KEYPAD Keys_Status;
	putsf(dev.DeviceName, 2);
	
	if ( dev.Read(REG_PRESSED_KEY, &PrKey, sizeof(PrKey)) == 0 ) 
	{
		if ( PrKey == '4')
		{
			putsf("PressedKey: 4", AUX_PORT);
		}
	}

	if ( dev.Read(REG_KEYS_STATUS, &Keys_Status, sizeof(Keys_Status)) == 0 ) 
	{
		if ( Keys_Status.FOUR == 1 )
		{
			putsf("Key 4 - pressed", AUX_PORT);
		}
	}
}

#endif
